import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-06-07
 * Time: 16:00
 */
class MobilePhone implements Comparable<MobilePhone>{
    private String type;
    private int price;

    public MobilePhone(String type, int price) {
        this.type = type;
        this.price = price;
    }

    @Override
    public int compareTo(MobilePhone o) {
        return price - o.price;
    }

    @Override
    public String toString() {
        return "型号：" +
                 type +
                "，价格：" + price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Map<String, List<Integer>> map = new TreeMap<>();
        List<String> list1 = new ArrayList<>();
        int line = 1;
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            if(str.equals("!!!!!")) {
                break;
            }
            list1.add(str);
            String[] strings = str.split(" ");
            for (String s :
                    strings) {
                if(map.containsKey(s)) {
                    if (map.get(s).contains(line))
                        continue;
                    map.get(s).add(line);
                } else {
                    List<Integer> index = new ArrayList<>();
                    index.add(line);
                    map.put(s, index);
                }
            }
            line++;
        }
//        List<Map.Entry<String, List<Integer>>> list2 = new ArrayList<>(map.entrySet());
//        for (Map.Entry<String, List<Integer>> t :
//                list2) {
//            System.out.println(t);
//        }
        for (Map.Entry<String, List<Integer>> t :
                map.entrySet()) {
            System.out.println(t);
        }
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            String[] strings = s.split(" ");
            Set<Integer> set = new TreeSet<>();
            Set<Integer> ans = new TreeSet<>();
            int flag  = 0;
            for (int i = 0; i < strings.length; i++) {
                if(map.containsKey(strings[i])) {
                    List<Integer> list4 = map.get(strings[i]);
                    if (set.isEmpty()) {
                        set.addAll(list4);
                    } else {
                        for (int j : list4){
                            if(set.contains(j)) {
                                ans.add(j);
                            }
                        }
                        flag++;
                    }
                }
            }
            if(flag == 0) {
                ans.addAll(set);
            }
            if(ans.isEmpty()) {
                System.out.println("found 0 results");
                continue;
            }
            System.out.println(ans);
            for (int i :
                    ans) {
                System.out.println("line " +( i) + ":" + list1.get(i - 1));
            }
        }
    }
    public static void main2(String[] args) {
        List<MobilePhone> list = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            list.add(new MobilePhone(scanner.next(), scanner.nextInt()));
        }
        System.out.println("排序前，链表中的数据：");
        for (MobilePhone m :
                list) {
            System.out.println(m);
        }
        Collections.sort(list);
        System.out.println("排序后，链表中的数据：");
        for (MobilePhone m :
                list) {
            System.out.println(m);
        }
        MobilePhone mobilePhone = new MobilePhone(scanner.next(), scanner.nextInt());
        for (MobilePhone m :
                list) {
            if (m.getPrice() == mobilePhone.getPrice()) {
                System.out.println(mobilePhone.getType() + "与链表中的" + m.getType() + "价格相同");
                return;
            }
        }
        System.out.println("链表中的对象，没有一个与" + mobilePhone.getType() + "价格相同的");
    }
    public static void main1(String[] args) {
        TreeSet<String> treeSet1 = new TreeSet<>();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext() && treeSet1.size() < 5) {
            treeSet1.add(scanner.next());
        }
        TreeSet<String> treeSet2 = new TreeSet<>();
        while (scanner.hasNext() && treeSet2.size() < 5) {
            treeSet2.add(scanner.next());
        }
        TreeSet<String> treeSet = new TreeSet<>();
        treeSet.addAll(treeSet1);
        treeSet.addAll(treeSet2);
        for (String s : treeSet) {
            System.out.println(s);
        }
    }
}
